package com.drawquest.gui.components;

import com.drawquest.gui.panels.CommentsPanel;
import com.drawquest.gui.panels.MainPanel;
import com.gooddies.events.BooleanEvent;
import com.gooddies.graphics.InteractiveIcon;
import com.gooddies.swing.swypepanel.SwypePanel;
import com.gooddies.wiring.Wiring;
import java.io.IOException;
import java.io.InputStream;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;

public class FooterPanel extends javax.swing.JPanel {

    public FooterPanel() {
        initComponents();
        ImageIcon todayIcon = loadImage("today.png");
        ImageIcon backIcon = loadImage("back.png");
        todayIconLabel.setInteractiveIcon(new InteractiveIcon(todayIcon));
        todayIconLabel.addClickEvent(new BooleanEvent() {

            @Override
            public boolean fireEvent(Object aThis) {
                today();
                return false;
            }
        });
        backIconLabel.setInteractiveIcon(new InteractiveIcon(backIcon));
        backIconLabel.addClickEvent(new BooleanEvent() {

            @Override
            public boolean fireEvent(Object aThis) {
                back();
                return false;
            }
        });
    }

    private void today() {
        MainPanel mainPanel = Wiring.getComponent(MainPanel.class);
        Wiring.getComponent(SwypePanel.class).pushComponent(mainPanel);
    }

    private void back() {
        CommentsPanel panel = Wiring.getComponent(CommentsPanel.class);
        Wiring.getComponent(SwypePanel.class).pushComponent(panel);
    }

    private ImageIcon loadImage(String path) {
        try {
            try (InputStream stream = this.getClass().getResourceAsStream("/com/drawquest/resources/" + path)) {
                return new ImageIcon(ImageIO.read(stream));
            }
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        todayIconLabel = new com.gooddies.graphics.LinkIconLabel();
        backIconLabel = new com.gooddies.graphics.LinkIconLabel();

        setBackground(new java.awt.Color(255, 255, 255));
        setBorder(new javax.swing.border.LineBorder(new java.awt.Color(204, 204, 204), 2, true));
        setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 0, 10));

        todayIconLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/drawquest/resources/today.png"))); // NOI18N
        add(todayIconLabel);

        backIconLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/drawquest/resources/back.png"))); // NOI18N
        add(backIconLabel);
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private com.gooddies.graphics.LinkIconLabel backIconLabel;
    private com.gooddies.graphics.LinkIconLabel todayIconLabel;
    // End of variables declaration//GEN-END:variables
}
